// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Compute a wild village
// -----------------------------------------------

private [
	"_vehicle",
	"_vehicles",
	"_isflat",
	"_position",
	"_location",
	"_kindofhouses"
];

_location     = _this select 0;
_kindofhouses = _this select 1;

if (typeName _location != "LOCATION") exitWith {
	hintC "computeavillage script: location parameter should be a location variable";
};

if (typeName _kindofhouses != "ARRAY") exitWith {
	hintC "computeavillage script: kindofhouse parameter should be an array variable";
};

if (count _kindofhouses == 0) exitWith {
	diag_log "WARCONTEXT: NO KIND OF HOUSES WERE SETTED";
};

_vehicles = [];

for "_i" from 0 to ceil(random 100) do {
	_position = (position _location) findEmptyPosition [(5 + random 10), 400];
	if (count _position > 0) then {
		if (count (_position nearRoads 15) == 0) then {
			_isflat = _position isFlatEmpty [5, 0, 0, 20, 0, false];  
			if (count _isflat != 0) then { 
				_vehicle = (_kindofhouses call BIS_fnc_selectRandom) createVehicle _position;
				_vehicle setDir (random 360);
				_vehicles  = _vehicles + [_vehicle];
			};
		};
	};
	sleep 0.005;
};

wcobjecttodelete  = wcobjecttodelete + _vehicles;

diag_log "WARCONTEXT: COMPUTING A VILLAGE";